<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of BScreenAddQueueLine
 *
 * @author I062261
 */
class BScreenAddQueueLine extends BUIScreen {

    public function render($data = null) {
        //parent::render($data);
        $this->addRenderView('addQueueLine', 'addQueueLineView', array('screen' => $this));
        //$this->startRender();
    }

    /**
     * 
     * @param type AddQueueLineFormModel
     */
    public function addQueueLine($basicModel, $resourceModel, $timeResourceModel, $queueStrategyModel) {
        $dataAdapter = Blyn::app()->getActiveServiceApp()->getDbAdapter();
        $service = Blyn::app()->getActiveService();
        $name = $basicModel->queueLineName;
        $description = $basicModel->queueLineDescription;

        $sQL_id = $dataAdapter->addServiceQueueLine($service, $name, $description);
        $resourceId = $dataAdapter->addServiceQueueLineResource($sQL_id, $service, $resourceModel->queueLineResourceName, $resourceModel->queueLineResourceMaxNumber, $resourceModel->queueLineResourceDescription);
        $timeResourceId = $dataAdapter->addQueueLineTimeResource(array(
            //'cyclePeriodExpression' => $model->queueLineCycleExpress,
            'serviceQueueLineId' => $sQL_id,
            'cycleLength' => $timeResourceModel->queueLineCycleLength,
            'cycleRepeatTime' => $timeResourceModel->queueLineCycleRepeatTimes,
            //'timeSlotPeriodExpression' => $model->timeSlotPeriodExpression,
            'startTime' => $timeResourceModel->queueLineStartTime,
            'endTime' => $timeResourceModel->queueLineEndTime,
            'allocateQueueStrategy' => $queueStrategyModel->allocateQueueStrategy,
            'makeQueueStrategy' => $queueStrategyModel->makeQueueStrategy,
            'timeSlotLength' => $queueStrategyModel->timeSlotLength,
            'processQueueStrategy' => $queueStrategyModel->processQueueStrategy,
            'makeQueueCycleLength' => $queueStrategyModel->makeQueueCycleLength,
            'makeQueueCycleOffset' => $queueStrategyModel->makeQueueCycleOffset,
            'makeQueueTimeSlotLength' => $queueStrategyModel->makeQueueTimeSlotLength,
            'makeQueueTimeSlotOffset' => $queueStrategyModel->makeQueueTimeSlotOffset,
            //'makeQueueCycleExpression' => $model->makeQueueCycleExpression,
            'processQueueCycleLength' => $queueStrategyModel->processQueueCycleLength,
            'processQueueCycleOffset' => $queueStrategyModel->processQueueCycleOffset,
            'processQueueTimeSlotLength' => $queueStrategyModel->processQueueTimeSlotLength,
            'processQueueTimeSlotOffset' => $queueStrategyModel->processQueueTimeSlotOffset,
                //'processQueueCycleExpression' => $model->processQueueCycleExpression,
                ));
    }

    public function addChildQueueLine($basicModel,$childModel) {
        $parentId = $childModel->parentQueueLine;
        $childQL_Name = $basicModel->queueLineName;
        $childQL_Description = $basicModel->queueLineDescription;

        //first create child QL
        $dataAdapter = Blyn::app()->getActiveServiceApp()->getDbAdapter();

        $childQLId = $dataAdapter->addServiceQueueLine(Blyn::app()->getActiveService(), $childQL_Name, $childQL_Description);
        $dataAdapter->addQueueLineChild($parentId, $childQLId);
    }

}

?>
